using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using LoD.Contracts;
using LoD.Contracts.MapEngine;


namespace LoD.WPClientLibrary.MapEngine {
    [DataContract]
    public class MapCell : IMapCell {
        public MapCell(int tileID) {
            this.BaseTiles = new List<int>();
            this.StackTiles = new List<int>();
            this.Tiles = new List<int>();

            this.TileID = tileID;
            this.Walkable = true;
            this.SlopeTile = TileSlope.None;
        }

        #region IMapCell Members

        [DataMember]
        public List<int> BaseTiles { get; set; }
        
        [DataMember]
        public List<int> StackTiles { get; set; }
        
        [DataMember]
        public List<int> Tiles { get; set; }

        [DataMember]
        public bool Walkable { get; set; }

        [DataMember]
        public TileSlope SlopeTile { get; set; }


        public int TileID {
            get {
                return this.BaseTiles.Any()
                           ? this.BaseTiles[0]
                           : 0;
            }
            set {
                if (this.BaseTiles.Any()) this.BaseTiles[0] = value;
                else this.AddBaseTile(value);
            }
        }

        public void AddBaseTile(int tileID) { this.BaseTiles.Add(tileID); }

        public void AddStackTile(int tileID) { this.StackTiles.Add(tileID); }

        public void AddTile(int tileID) { this.Tiles.Add(tileID); }

        public void RemoveBaseTile(int tileID) { this.BaseTiles.Remove(tileID); }

        public void RemoveStackTile(int tileID) { this.StackTiles.Remove(tileID); }

        public void RemoveTile(int tileID) { this.Tiles.Remove(tileID); }

        #endregion
    }
}